package com.demo.thread.future;

import java.util.concurrent.*;

/**
 * @author : YU.TAN
 * @date : 2021/11/2 14:27
 * runAsync()是CompletableFuture最常用的方法之一，它可以接收一个待运行的任务并返回一个CompletableFuture
 */
public class CompletableFutureA {
//    int cpuNum = Runtime.getRuntime().availableProcessors();
//    int threadNum = cpuNum * 2 + 1;
//int CORE_POOL_SIZE = (Runtime.getRuntime().availableProcessors()) * 2 + 1;
//    int MAX_POOL_SIZE = CORE_POOL_SIZE - 1;
//    int KEEP_ALIVE_TIME = 60;
//
//    ThreadPoolExecutor poolExecutor =
//            new ThreadPoolExecutor(CORE_POOL_SIZE, MAX_POOL_SIZE, KEEP_ALIVE_TIME, TimeUnit.SECONDS,
//                    new LinkedBlockingQueue<>(10000),
//                    Executors.defaultThreadFactory(),
//                    new ThreadPoolExecutor.AbortPolicy());



    public static void main(String[] args) {


        /**
         * 写法一
         */
        CompletableFuture.runAsync(new Runnable() {
            @Override
            public void run() {
                System.out.println("runAsync() 测试！");
            }
        });

        /**
         * 写法二
         */
        CompletableFuture.runAsync(() -> System.out.println("runAsync() 测试！"));




//        /**
//         * 写法三，引入线程池
//         */
//        CompletableFuture.runAsync(new Runnable() {
//            @Override
//            public void run() {
//                System.out.println("runAsync() 测试！");
//            }
//        },poolExecutor);

    }
}
